/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package estg.dae.projecto.bank.controllers;

import estg.dae.projecto.bank.data.ClientDaoLocal;
import estg.dae.projecto.bank.model.Account;
import estg.dae.projecto.bank.model.Client;
import java.util.Collection;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Marco
 */
@Stateless
public class ClientControllerBean implements ClientControllerLocal {

    @EJB
    private ClientDaoLocal clientDao;
    @EJB
    private AccountControllerLocal accountController;

    public boolean exists(String nif) {
        return clientDao.exists(nif);
    }

    public Client get(String nif) {
        return clientDao.get(nif);
    }

    public Client get(long id) {
        return clientDao.get(id);
    }

    public void save(Client client, int agency) {
        clientDao.save(client);
        Account account = accountController.createAccount(client, agency, 0.0);
        client = account.getClient();
    }

    public void update(Client client) {
        clientDao.update(client);
    }

    public void delete(Client client) {
        clientDao.delete(client);
    }

    public Collection<Client> getAll() {
        return clientDao.getAll();
    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
 
}
